
//
// 120312 - AH - (Garage) Created.
// 120313 - AH - Made Serializable and toString().
//

package org.soekrat.server.serialization;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *   Describes input from the visitor.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LCC) 
 */
public final class ChatInputSerializable implements Serializable
{
  private static final long serialVersionUID=-8126153736196872750L;

  private Date date=new Date();
  
  private List<String> inputs=null;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public ChatInputSerializable(){}
  
  /**
   * <p>
   *   Gets creation date.
   * </p>
   * @return {@link Date}.
   */
  public Date date(){ return date; }
  
  /**
   * <p>
   *   Adds input from the visitor,
   * </p>
   * @param input
   * @return
   */
  public ChatInputSerializable addInput(String input)
  {
    if (input==null)
    {
      throw new NullPointerException("input");
    }
    
    if (inputs==null) inputs=new ArrayList<String>();
    inputs.add(input);
    return this;
  }
  
  private static final String[] E_STRING_A=new String[0];
  
  /**
   * <p>
   *   Gets inputs from visitor.
   * </p>
   * @return Input
   *         {@link String}s.
   */
  public String[] getInputs()
  { 
    return inputs==null ? E_STRING_A : inputs.toArray(E_STRING_A);
  }
  
  @Override
  public String toString() 
  {
    StringBuilder sb=new StringBuilder();
    
    boolean first=true;
    if (date!=null)
    {
      sb.append("date=").append(date);
      first=false;
    }
    if (inputs!=null)
    {
      if (!first) sb.append(", ");
      sb.append("inputs=").append(inputs);
      first=false;
    }
    
    return sb.toString();
  }
  
}
